// store/modules/balanceAndPoints.js

export default {
    namespaced: true, // 启用命名空间
    state: {
        balance: 0,
        points: 0,  // 设置初始积分为 20
        isVip: false // 新增字段：是否是 VIP 用户
    },
    getters: {
        balance: state => state.balance,
        points: state => state.points
    },
    mutations: {
        setBalance(state, balance) {
            state.balance = balance;
        },
        setPoints(state, points) {
            state.points = points;
        },
        setIsVip(state, isVip) {
            state.isVip = isVip;
        },
    },
    actions: {
        updateBalance({ commit }, balance) {
            commit('setBalance', balance);
        },
        updatePoints({ commit, state }, amount = 0) {
            const newPoints = state.points + amount;
            if (newPoints >= 100 && !state.isVip) {
                commit('setIsVip', true);
            }
            commit('setPoints', newPoints);
        },
    }
}
